Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom Jinja filters #477

Closed
wants to merge 1 commit into from

Conversation

mattvonrocketstein
Copy link

@mattvonrocketstein mattvonrocketstein commented Oct 1, 2018

Corresponding issue is here. Syndicating content: My use-case involves adding new custom Jinja filters into projects using the v1 releases of sceptre, which I haven't found a supported way to accomplish.

I think this should work in way similar to hooks/resolvers, i.e. loading this project-specific functionality from "jinja_filters" folder underneath the sceptre root.

This PoC here is rough but working. Mostly this approach feels bad because I can't see how to access any kind of global sceptre config to get at information like the --dir argument applied by the CLI. I've had to configure the directory for external jinja filters from an environment variable for now to work around this.

Obviously even if smoothed this pull would needs corresponding docs changes. Waiting for some guidance about how to move forward and whether/how this could be accepted into 1.x mainline (my org probably can't commit to v2 soon)

if hasattr(self, '_jinja_filters'):
return self._jinja_filters
# load jinja filters if not already cached
env_var_name = 'SCEPTRE_JINJA_FILTER_ROOT'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be reaching env_vars directly, can we read this as environment config for consistency

Copy link
Author

@mattvonrocketstein mattvonrocketstein Oct 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How exactly should that be done? Template() seems to only be instantiated with with scepre_user_data, not environment_config. See also this related issue.

Does a path from environment_config or stack_config actually help here? I think what is really needed is the exact value passed from the CLI argument --dir, because even given an environment or stack path, if env folders are nested then one couldn't be sure how far to go back up the directory tree to get to the sceptre root (i.e. the folder that holds config, template, hooks, resolvers, and by symmetry jinja_filters).

msg = 'loading jinja filters from: {}'
self.logger.debug(msg.format(filter_dir))
self._jinja_filters = {}
for fpath in glob.glob(os.path.join(filter_dir, '*.py')):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would be done using entry points, as per the new hooks, resolves code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an example of that in v1, or would this need backport from v2?

@ngfgrant ngfgrant changed the title PoC fix for Issue 476 Support for custom Jinja filters Oct 31, 2018
@ngfgrant
Copy link
Contributor

Closing as won't support in v1. v1 EOL as of tomorrow.

Would consider support for v2?

@ngfgrant ngfgrant closed this May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants